import unittest
from unittest.mock import patch
from datetime import datetime
import main


class TestMain(unittest.TestCase):

    class MockDateTime(datetime):
        @classmethod
        def now(cls, tz = None):
            return cls(2025, 2, 26)

    def test_calculate_age(self):
        # Mock the current date to a fixed value for consistent testing
        with patch('main.datetime', new=self.MockDateTime):

            # Test case 1: Birthday has passed this year
            birthday1 = '2000-01-01'
            expected_age1 = 2025 - 2000
            result1 = main.calculate_age(birthday1)
            self.assertEqual(result1, expected_age1)
            print(f"Test Case 1: For birthday {birthday1}, expected age {expected_age1}, got {result1}. Test passed.")
            print(f"测试用例 1: 对于生日 {birthday1}，预期年龄 {expected_age1}，实际得到 {result1}。测试通过。")

            # Test case 2: Birthday is yet to come this year
            birthday2 = '2000-03-01'
            expected_age2 = 2025 - 2000 - 1
            result2 = main.calculate_age(birthday2)
            self.assertEqual(result2, expected_age2)
            print(f"Test Case 2: For birthday {birthday2}, expected age {expected_age2}, got {result2}. Test passed.")
            print(f"测试用例 2: 对于生日 {birthday2}，预期年龄 {expected_age2}，实际得到 {result2}。测试通过。")

            # Test case 3: Birthday is today
            birthday3 = '2000-02-26'
            expected_age3 = 2025 - 2000
            result3 = main.calculate_age(birthday3)
            self.assertEqual(result3, expected_age3)
            print(f"Test Case 3: For birthday {birthday3}, expected age {expected_age3}, got {result3}. Test passed.")
            print(f"测试用例 3: 对于生日 {birthday3}，预期年龄 {expected_age3}，实际得到 {result3}。测试通过。")

            # Test case 4: Birthday on a leap year
            birthday4 = '2000-02-29'
            expected_age4 = 2025 - 2000 - 1 if (2, 26) < (2, 29) else 2025 - 2000
            result4 = main.calculate_age(birthday4)
            self.assertEqual(result4, expected_age4)
            print(f"Test Case 4: For birthday {birthday4}, expected age {expected_age4}, got {result4}. Test passed.")
            print(f"测试用例 4: 对于生日 {birthday4}，预期年龄 {expected_age4}，实际得到 {result4}。测试通过。")

            # Test case 5: Birthday in the same year as the current year
            birthday5 = '2025-01-01'
            expected_age5 = 0 if (2, 26) < (1, 1) else 2025 - 2025
            result5 = main.calculate_age(birthday5)
            self.assertEqual(result5, expected_age5)
            print(f"Test Case 5: For birthday {birthday5}, expected age {expected_age5}, got {result5}. Test passed.")
            print(f"测试用例 5: 对于生日 {birthday5}，预期年龄 {expected_age5}，实际得到 {result5}。测试通过。")


if __name__ == '__main__':
    unittest.main()